package com.briup.corejava.day15;

import com.briup.corejava.day10.pojo.Student;

/**
 * 自定义异常
 * 编译型异常：继承自Exception
 * 运行时异常：继承自RuntimeException
 */
public class Test4 {
    public static void main(String[] args) {
        Student s = new SubStudent();
        s.setName("张三");
        s.setAge(500);
        System.out.println(s);
    }
}
class SubStudent extends Student{
    @Override
    public void setAge(Integer age) {
        // 这里需要判断age的有效性
        if(age>=4 && age <=70){
            super.setAge(age);
        }else {
            throw new AgeOutOfBoundsException("年龄不符合要求");
        }
    }
}
// 定义运行时异常
class AgeOutOfBoundsException extends RuntimeException{
    public AgeOutOfBoundsException(){}
    public AgeOutOfBoundsException(String msg){
        super(msg);
    }
}
